﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TGIApp.Model;

namespace TGIApp.Web.Controllers
{
    public class TicketQuotaController : Controller
    {
        //
        // GET: /TicketQuota/

        public ActionResult Index()
        {
            var proxy = new Proxy.ServiceProxy();
            var ticketQuotas = proxy.GetAllTicketQuotas();
            return View(ticketQuotas);
        }

        //
        // GET: /TicketQuota/Details/5

        public ActionResult Details(int id)
        {
            var proxy = new Proxy.ServiceProxy();
            var ticketQuota = proxy.GetTicketQuotaLoadedById(id);
            return View(ticketQuota);
        }

        //
        // GET: /TicketQuota/Create

        public ActionResult Create()
        {
            var proxy = new Proxy.ServiceProxy();
            ViewBag.AgentBranches = proxy.GetAllAgentBranches();
            ViewBag.TicketTypesWithEventVenue = from ticketType in proxy.GetAllTicketTypesWithEventVenue() select new { Id = ticketType.Id, ShowNameNClass = ticketType.EventVenue.ShowName + "|" + ticketType.Class };
             return View();
        } 

        //
        // POST: /TicketQuota/Create

        [HttpPost]
        public ActionResult Create(TicketQuota ticketQuota)
        {
            if (ModelState.IsValid)
            {
                ITgiService proxy = new Proxy.ServiceProxy();
                proxy.CreatTicketQuota(ticketQuota);
            }
            return RedirectToAction("Index");
        }
        
        //
        // GET: /TicketQuota/Edit/5
 
        public ActionResult Edit(int id)
        {
            var proxy = new Proxy.ServiceProxy();
            ViewBag.AgentBranches = proxy.GetAllAgentBranches();
            ViewBag.TicketTypesWithEventVenue = from ticketType in proxy.GetAllTicketTypesWithEventVenue() select new { Id = ticketType.Id, ShowNameNClass = ticketType.EventVenue.ShowName + "|" + ticketType.Class };
            var ticketQuota = proxy.GetTicketQuotaById(id);
            return View(ticketQuota);
        }

        //
        // POST: /TicketQuota/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, TicketQuota ticketQuota)
        {
            if (ModelState.IsValid)
            {
                ITgiService proxy = new Proxy.ServiceProxy();
                proxy.UpdateTicketQuota(ticketQuota);
            }
            return RedirectToAction("Index");
        }

        //
        // GET: /TicketQuota/Delete/5
 
        public ActionResult Delete(int id)
        {
            ITgiService proxy = new Proxy.ServiceProxy();
            var ticketQuota = proxy.GetTicketQuotaLoadedById(id);
            return View(ticketQuota);
        }

        //
        // POST: /TicketQuota/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, TicketQuota ticketQuota)
        {
            ITgiService proxy = new Proxy.ServiceProxy();
            proxy.DeleteTicketQuotaById(id);
            return RedirectToAction("Index");
        }
    }
}
